package priv.hehe.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sound.midi.Soundbank;

import priv.hehe.entry.Emplooy;
import priv.hehe.util.JdbcUtil;
import priv.hehe.util.JdbcUtil.JdbcVisitor;

/*+--------+---------------+------+-----+---------+----------------+
| Field  | Type          | Null | Key | Default | Extra          |
+--------+---------------+------+-----+---------+----------------+
| e_id   | int(11)       | NO   | PRI | NULL    | auto_increment |
| e_name | varchar(200)  | YES  |     | NULL    |                |
| salary | decimal(10,0) | YES  |     | NULL    |                |
| l_id   | int(11)       | NO   |     | NULL    |                |
| d_id   | int(11)       | YES  | MUL | NULL    |                |
| sex    | smallint(1)   | YES  |     | NULL    |                |
| age    | smallint(3)   | YES  |     | NULL    |                |
| phone  | char(11)      | YES  |     | NULL    |                |
| pass   | char(32)      | YES  |     | NULL    |                |
+--------+---------------+------+-----+---------+----------------+*/
public class EmplooyService {
	
	public static void main(String[] args) throws ClassNotFoundException {
		EmplooyService emplooyService = new EmplooyService();
		emplooyService.selectAll();
	}

	public List<Emplooy> selectAll() throws ClassNotFoundException{
		String sql="select * from emplooy";
		List<Emplooy> list=new ArrayList<Emplooy>();
		JdbcUtil.queryAll(sql, new JdbcVisitor() {
			@Override
			public Object handlerResult(ResultSet resultSet) {
				try {
					while(resultSet.next()){
						Emplooy emplooy = new Emplooy();
						emplooy.setdId(resultSet.getInt("e_id"));
						emplooy.setAge(resultSet.getInt("age"));
						emplooy.setdId(resultSet.getInt("d_id"));
						emplooy.seteName(resultSet.getString("e_name"));
						emplooy.setPhone(resultSet.getString("phone"));
						emplooy.setSalary(resultSet.getDouble("salary"));
						emplooy.setPass(resultSet.getString("pass"));
						list.add(emplooy);
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				return null;
			}
		});
		return list;
	}
	
}
